package org.jivesoftware;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;

import javax.swing.ImageIcon;
import javax.swing.JButton;

import org.jivesoftware.resource.SparkRes;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.RoundRectangle2D;
import javax.swing.JButton;

public class LoginButton extends JButton {
	private static final long serialVersionUID = 39082560987930759L;
	public static final Color BUTTON_COLOR1 = new Color(250, 216, 144);
	public static final Color BUTTON_COLOR2 = new Color(244, 163, 13);
	public static final Color BUTTON_FOREGROUND_COLOR = Color.WHITE;
	private boolean hover;

	public LoginButton() {
//		setFont(new Font("system", Font.PLAIN, 12));
//		setBorderPainted(true);
//		setForeground(BUTTON_COLOR2);
//		setFocusPainted(false);
//		setContentAreaFilled(true);
//		addMouseListener(new MouseAdapter() {
//			@Override
//			public void mouseEntered(MouseEvent e) {
//				setForeground(BUTTON_FOREGROUND_COLOR);
//				hover = true;
//				repaint();
//			}
//
//			@Override
//			public void mouseExited(MouseEvent e) {
//				setForeground(BUTTON_COLOR2);
//				hover = false;
//				repaint();
//			}
//		});
	}
	 private ImageIcon icon = SparkRes.getImageIcon(SparkRes.LOGIN_BUTTON);
	 private ImageIcon hoverIcon=SparkRes.getImageIcon(SparkRes.LOGIN_BUTTON_HOVER);
	 private ImageIcon selectedIcon=SparkRes.getImageIcon(SparkRes.LOGIN_BUTTON_SELECTED);
//	 private ImageIcon iconIn=icon;
	 public void paintComponent(Graphics g){
		 newpaint(g,icon);
		 if(getModel().isRollover()){
			 newpaint(g,hoverIcon);
		 }if(getModel().isPressed()){
			 newpaint(g,selectedIcon);
		 }
	 }
	 public void newpaint(Graphics g,ImageIcon icon){
		 Image backgroundImage = icon.getImage();
		 double scaleX = getWidth()
		 / (double) backgroundImage.getWidth(null);
		 double scaleY = getHeight()
		 / (double) backgroundImage.getHeight(null);
		 AffineTransform xform = AffineTransform.getScaleInstance(scaleX,
		 scaleY);
		 ((Graphics2D) g).drawImage(backgroundImage, xform, this);
	 }
}

// public class LoginButton extends JButton {
// private JButton loginButton;
// private boolean hovered;
// private ImageIcon icon = SparkRes.getImageIcon(SparkRes.LOGIN_BUTTON);
// private ImageIcon
// hoverIcon=SparkRes.getImageIcon(SparkRes.LOGIN_BUTTON_HOVER);
// private ImageIcon iconIn=icon;
//
// public void paintComponent(Graphics g){
// paintComponent(g, iconIn);
// }
// public void paintComponent(Graphics g,ImageIcon iconIn){
// Image backgroundImage = iconIn.getImage();
// double scaleX = getWidth()
// / (double) backgroundImage.getWidth(null);
// double scaleY = getHeight()
// / (double) backgroundImage.getHeight(null);
// AffineTransform xform = AffineTransform.getScaleInstance(scaleX,
// scaleY);
// ((Graphics2D) g).drawImage(backgroundImage, xform, this);
//		
// }
// public void rePaintButton(ImageIcon icon){
// setButtonImage(icon);
// repaint();
// }
// private void setButtonImage(ImageIcon icon){
// this.icon=icon;
//		
// }
// }
// public LoginButton() {
//
// loginButton = new JButton("denglu");
// loginButton.setContentAreaFilled(false);
// loginButton.addMouseListener(new MouseListener() {
//			
// @Override
// public void mouseReleased(MouseEvent e) {
// // TODO Auto-generated method stub
//				
// }
//			
// @Override
// public void mousePressed(MouseEvent e) {
// // TODO Auto-generated method stub
//				
// }
//			
// @Override
// public void mouseExited(MouseEvent e) {
// // TODO Auto-generated method stub
// System.out.println("MouseExited now");
// iconIn.setImage(icon.getImage());
// repaint();
//				
// }
//			
// @Override
// public void mouseEntered(MouseEvent e) {
// // TODO Auto-generated method stub
// System.out.println("MouseEntered now");
// iconIn.setImage(iconHover.getImage());
// repaint();
//				
//				
// }
//			
// @Override
// public void mouseClicked(MouseEvent e) {
// // TODO Auto-generated method stub
//				
// }
// });
// // loginButton.setIcon(icon);
//		
// }
// public void setIcon(){
// ImageIcon icon = new ImageIcon("loginbutton.png");
// loginButton.setIcon(icon);
// }
// public void setHoverIcon(){
// ImageIcon rolloverIcon = new ImageIcon("loginbutton_hover.png");
// loginButton.setRolloverIcon(rolloverIcon);
//		
// }
// public void setPressedIcon(){
// ImageIcon pressedIcon=new ImageIcon("loginbutton_hover.png");
// loginButton.setPressedIcon(pressedIcon);
// }
// public void setSelectedIcon(){
// ImageIcon selectedIcon = new ImageIcon(
// "loginbutton_SelectedAndHover.png");
// loginButton.setSelectedIcon(selectedIcon);
// }
// }
